﻿using DX_Recognize.Common;
using DX_Recognize.Entitys;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DX_Recognize.View
{
    public partial class SteelWindow : Form
    {
        private int operIndex = -1;
        public SteelWindow()
        {
            InitializeComponent();
            this.Hide();
        }

        public event Action<string,string,int> SteelAction;

        //设置原始下拉选项
        public void SetOriginOption(int targetIndex)
        {
            operIndex = targetIndex;
            string targetBoardName = AssemblyShareData.AUIBlueSectionList[targetIndex].BoardName;
            this.BoardNameLabel.Text = targetBoardName;
            this.Show();
        }

        private void CannelBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void SteelWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        private void ComfirmBtn_Click(object sender, EventArgs e)
        {
            string steeltext = SteelBox.Text;
            var targetItem = SteelBox.SelectedItem;
            string ItemNumber = ((StandardSteel)targetItem).ItemNumber;
            string ItemDesc = ((StandardSteel)targetItem).ItemDesc;
            SteelAction?.Invoke(ItemNumber, ItemDesc, operIndex);
            this.Hide();
        }

        private void SteelBox_TextUpdate(object sender, EventArgs e)
        {
            string SteelSearchText = SteelBox.Text;
            List<StandardSteel> OriginList = ParamsConfigData.StandardSteelList;
            List<StandardSteel> TargetList = new List<StandardSteel>();
            for (int i = 0; i < OriginList.Count; i++)
            {
                Boolean F = OriginList[i].ItemDesc.Contains(SteelSearchText);
                if (F)
                    TargetList.Add(OriginList[i]);
            }
            if (SteelBox.Items.Count > 0)
                SteelBox.Items.Clear();
            SteelBox.Items.AddRange(TargetList.ToArray());
            SteelBox.DisplayMember = "ItemDesc";
            SteelBox.ValueMember = "ItemNumber";
            SteelBox.DroppedDown = true;
            Cursor = Cursors.Default;
            SteelBox.Text = SteelSearchText;
            SteelBox.SelectedValue = null;
            SteelBox.Select(SteelBox.Text.Length, 0);
        }

  

    }
}
